package ah.szxy;

import ah.szxy.model.User;
import ah.szxy.service.MessageSendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class ProduceApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProduceApplication.class ,args) ;
    }

    @Autowired
    private MessageSendService messageSendService ;

    /**
     * 发送字符串
     * @param msg
     * @return
     */
    @GetMapping("/send/txt/{msg}")
    public ResponseEntity<String> sendTextMsg(@PathVariable("msg")String msg){
        messageSendService.send(msg);
        return ResponseEntity.ok().body("发送成功") ;
    }

    /**
     * 发送带tag的消息
     * @param msg
     * @param tag
     * @return
     */
    @GetMapping("/send/{tag}/{msg}")
    public ResponseEntity<String> sendTextMsg(
            @PathVariable("msg")String msg,
            @PathVariable("tag") String tag){

        messageSendService.send(msg,tag);
        return ResponseEntity.ok().body("发送成功") ;
    }


    @GetMapping("/send/object")
    public ResponseEntity<String> sendObject(User user, String tag){
        messageSendService.sendObject(user,tag);
        return ResponseEntity.ok().body("发送成功") ;
    }

    @GetMapping("/send/trans")
    public ResponseEntity<String> sendTransactionMsg(String msg ,int type){
        messageSendService.sendTransactionMsg(msg,type);
        return ResponseEntity.ok("发送成功") ;
    }

    @GetMapping("/send/pull")
    public ResponseEntity<String> sendPull(String msg ){
        messageSendService.sendMassiveMsg(msg);
        return ResponseEntity.ok("发送成功") ;
    }


}
